import request from '@/config/axios'
import type {UpdateUserResponse, UserVoInner} from '@/model/user-import'

export const loginApi = (loginForm: LoginForm) => {
	return request.post<UserVoInner>({
		url: '/login',
		data: loginForm
	})
}

export const logoutApi = () => {
	return request.post({
		url: '/logout'
	})
}

export const saveUserApi = (data: UserForm) => {
	return request.post<UpdateUserResponse | undefined>({
		url: '/system/sys-user/saveUser',
		data
	})
}

export const deleteUserApi = (id: number) => {
	return request.delete({
		url: '/system/sys-user/deleteUser/' + id
	})
}

export const getAllRoleApi = () => {
	return request.post<SysRole[]>({
		url: '/system/sys-user/readOnly/getAllRole'
	})
}

export const getAllRoleByUserIdApi = (userId: number) => {
	return request.get<SysRole[]>({
		url: '/system/sys-user/readOnly/getAllRoleByUserId/' + userId
	})
}

export const updateUserValidApi = (data: { id: number, valid: number }) => {
	return request.put({
		url: '/system/sys-user/updateUserValid',
		data
	})
}

export const clearUserDataApi = (userId: number) => {
	return request.delete({
		url: '/system/sys-user/clearUserData/' + userId
	})
}
